package com.ftx.controller.base;

import com.alibaba.fastjson.JSON;
import com.google.common.util.concurrent.RateLimiter;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.*;
import java.util.zip.GZIPOutputStream;

/**
 * Created by fengtingxin on 2019/1/17.
 */

//@Controller
//@RequestMapping("/testController")
public class Test {


    private static final String ARTICLE_ID = "article_id";

    public static void main(String[] args) throws IOException{
        Integer ll = 1;
        Integer aa = ll;
        switch (ll)
        {
            case 1:aa =2 ; break;
            case 2: aa = 3; break;
            default:
        }
        System.out.println(aa);



        List<String> list = new ArrayList<>();
        list.add("100");
        list.add("100");
        list.add("101");
        HashMap<Integer,Integer> sendPay = new HashMap<>();
        sendPay.put(1,2);
        sendPay.put(2,4);
        sendPay.put(3,2);
        String temp = JSON.toJSONString(sendPay);

        System.out.println(new HashSet<>(list));

        System.out.println( 1 ^ 2);
        int a = 1;
        String binaryString = Integer.toBinaryString(a);
        System.out.println(binaryString);
        System.out.println(Integer.toBinaryString(4));


        //f14beee162e3b6ebfd965803b6ba503d
        ;
        System.out.println(new String(Base64.getDecoder().decode("f14beee162e3b6ebfd965803b6ba503d")));

//
//
//        System.out.println(UUID.randomUUID().toString().substring(0,16));
//
//        StringBuilder invoiceCode = new StringBuilder(); //发票代码
//        StringBuilder invoiceNumber = new StringBuilder(); //发票号码
//        List<Article> articles = new ArrayList<>();
//        Article article = new Article();
//        article.setArticleIntroduce("111");
//        article.setContent("content");
//        article.setId(112L);
//        articles.add(article);
//        Article article1 = new Article();
//        article1.setArticleIntroduce("111");
//        article1.setContent("content");
//        article1.setId(113L);
//        articles.add(article1);
//
//
//        for (int i = 0; i < articles.size() ; i++){
//            if (112L == articles.get(i).getId()){
//                articles.add(articles.size()-1, articles.remove(i));
//                break;
//            }
//        }
//
//        for (int i = 0; i < articles.size() ; i++){
//            System.out.println(articles.get(i).getId());
//        }
//
//
////        articles.stream().forEach(it -> {
////            if (StringUtils.isNotBlank(it.getArticleIntroduce())){
////                invoiceCode.append(it.getArticleIntroduce()).append(",");
////            }
////            System.out.println();
////            if (it.getContent() != null){
////                invoiceNumber.append(it.getContent()).append(",");
////            }
////        });
////        int _ia = 12;
////
////        System.out.println("invoiceCode is {}" + invoiceCode);
////        System.out.println("invoiceNumber is {}" + invoiceNumber);
////        invoiceCode.deleteCharAt(invoiceCode.length()-1);
////        invoiceNumber.deleteCharAt(invoiceNumber.length()-1);
////
////        System.out.println("invoiceCode is {}" + invoiceCode);
////        System.out.println("invoiceNumber is {}" + invoiceNumber);
//        testObject(null);
//        int array[] = new int[3];
//        array[0] = 2;
//        array[1] = 3;
//        array[2] = 1;
//        String string = "啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦";
//        System.out.println("string.length " + string.length());
//        System.out.println("string.length gbk" + string.getBytes("GBK").length);
//        Set<Integer> set = new HashSet<>();
//        System.out.println(JSON.toJSON(array));
//        System.out.println(1 << (4 - 2));
////        List<Integer> testList = new ArrayList<>();
////        Set<Integer> result = new HashSet<>();
////        Integer[] temp =  (Integer[]) result.toArray();
////        Iterator<Integer> it = result.iterator();
////
////        testList.add(0,0);
////        testList.add(1,1);
////        testList.add(2,2);
////        testList.add(3,3);
////        testList.add(4,4);
////        System.out.println(testList);
//
//
//
//        Random random = new Random();
//        System.out.println(random.nextInt(1));;
//
//        String aaa = ":[\"http://storage.jd.com/eicore-fm.jd.com/011001900311-70996295.pdf?Expires=2513235042&AccessKey=bfac05320eaf11cc80cf1823e4fb87d98523fc94&Signature=YpjAcMHhQIMjpU3Pi09e76znQmI%3D\",\"http://storage.jd.com/eicore-fm.jd.com/011001900411-46539183.pdf?Expires=2513235042&AccessKey=bfac05320eaf11cc80cf1823e4fb87d98523fc94&Signature=BJzGanW%2BmGzbVcjlUEzTB3r0oHk%3D\",\"http://storage.jd.com/eicore-fm.jd.com/011001900311-71011367.pdf?Expires=2513235042&AccessKey=bfac05320eaf11cc80cf1823e4fb87d98523fc94&Signature=LM%2BRxa%2BDnaheHG9bMWhOf5oOwMs%3D\",\"http://storage.jd.com/eicore-fm.jd.com/011001900311-70956979.pdf?Expires=2513235041&AccessKey=bfac05320eaf11cc80cf1823e4fb87d98523fc94&Signature=GhEJTYOqfhX%2FL4cUB17jzlrDlWg%3D\",\"http://storage.jd.com/eicore-fm.jd.com/011001900311-70977515.pdf?Expires=2513235041&AccessKey=bfac05320eaf11cc80cf1823e4fb87d98523fc94&Signature=L5WQm3K%2FWXxXjXN9OL9hRSxDn%2Fs%3D\",\"http://storage.jd.com/eicore-fm.jd.com/011001900411-46580357.pdf?Expires=2513235042&AccessKey=bfac05320eaf11cc80cf1823e4fb87d98523fc94&Signature=%2FdrnlUydSFHpOm8vS6A7wFvUvC8%3D\",\"http://storage.jd.com/eicore-fm.jd.com/011001900411-46855166.pdf?Expires=2513235042&AccessKey=bfac05320eaf11cc80cf1823e4fb87d98523fc94&Signature=ID5fHzF%2FR%2BUSVu9MVyttpuwJi%2FM%3D\"],\"operateType\":1,\"sourceSystemId\":32,\"sourceNo\":\"51003786455\"}";
//        System.out.println(compress(aaa));
//        final RateLimiter limiter = RateLimiter.create(1);
//        for (int i = 0; i < 10 ;i ++){
//            System.out.println(limiter.tryAcquire());
//            System.out.println(111);
//        }
//        testAcquire();
    }

    public static void testObject(Object object){
        System.out.println("test object");
    }

    public static void testObject(double[] object){
        System.out.println("test double");
    }


    public static void testAcquire() {
        RateLimiter limiter = RateLimiter.create(1);

        for(int i = 1; i < 10; i = i + 2 ) {
            double waitTime = limiter.acquire(i);
            System.out.println("cutTime=" + System.currentTimeMillis() + " acq:" + i + " waitTime:" + waitTime);
        }
    }

    public static String compress(String str) throws IOException {
        if (str == null || str.length() == 0) {
            return str;
        }
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        GZIPOutputStream gzip = new GZIPOutputStream(out);
        gzip.write(str.getBytes());
        gzip.close();
        return out.toString("ISO-8859-1");
    }


}
